import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

# Next.js

<Tabs>
<TabItem value="app" label="App Router">

```typescript title="app/api/queues/sample/route.ts"
import { Queue } from "quirrel/next-app";

export const sampleQueue = Queue(
  "api/queues/sample",
  async (job, meta) => {
    // do something
  }
);

export const POST = sampleQueue;
```

Creates a new Queue.
Make sure to export it from a [Route Handler](https://nextjs.org/docs/app/building-your-application/routing/router-handlers), otherwise it won't work.

</TabItem>
<TabItem value="page" label="Pages Router">

```typescript title="pages/api/queues/sample.ts"
import { Queue } from "quirrel/next-pages";

export default Queue("api/queues/sample", async (job, meta) => {
  // do something
});
```

Creates a new Queue.
Make sure to export it from an [API Route](https://nextjs.org/docs/api-routes/introduction), otherwise it won't work.

</TabItem>
</Tabs>

#### Parameters

```ts
function Queue<T>(
  path: string,
  worker: (job: T, meta: JobMeta): Promise<void>,
  defaultJobOptions?: { exclusive?: boolean }
): QueueInstance<T>
```


| Parameter           | Usage                                                           |
| ------------------- | --------------------------------------------------------------- |
| `path`              | The route that this queue is reachable at.                      |
| `worker`            | a function that takes the job's payload and returns a `Promise` |
| `defaultJobOptions` | Optional. Use to set default options applied to every job.      |
